/*
 * 功能    : 登录表单验证、提交
 * 编辑时间：2014-03-05
 * 作者    ：Arvin.chen@zkteco.com
 */

$(function(){
    $("#wap_login").unbind().click(function(){
        usern=$("#wap_username").val();
        pwd=$("#wap_pwd").val();
        post_url="/wap/login/?username="+usern+"&password="+pwd;
        redirect_url="/wap/index/"
        $.ajax({
            url:post_url,
            type:"POST",
            dataType:"html",
            success:function(msg){
                if(msg=='ok'){
                   var index=window.location.href.indexOf("?next=");
                   var wap_index=window.location.href.indexOf("wap");
                   if(index!=-1){
                     var href=window.location.href.substring(index+6);
                     window.location.href=href;
                    }else{
                     window.location.href=redirect_url;
                    }
                }else{
                    $("#error_info").empty();
                    $("#error_info").append('<ul><li>'+msg+'</li></ul>');
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
            }
        });
    });
    $("#logout").unbind().click(function(){
        var logout_url="/wap/wap_loginout/";
        redirect_url="/wap/";
        $.ajax({
            url:logout_url,
            type:"POST",
            dataType:"html",
            success:function(msg){
                if(msg=="ok"){
                    window.location.href=redirect_url;
                }
            },
             error: function(XMLHttpRequest, textStatus, errorThrown){
            }
        });
    });
});
